﻿#ifndef CATNETWORK_H
#define CATNETWORK_H

#include <QObject>

class QHostInfo;

class CatNetWork : public QObject
{
    Q_OBJECT
    Q_ENUMS(IP)
public:
    explicit CatNetWork(QObject *parent = nullptr);
    ~CatNetWork();

public:
    enum IP {
        V4,
        V6
    };
    void lookupHost(QString host);

    // 获取当前系统 所有可用的Ipv4地址
    QList<QString> GetAllIpaddressIpv4( void ) const;
    // 获取当前系统 所有可用的Ipv6地址
    QList<QString> GetAllIpaddressIpv6( void ) const;
    // 获取当前系统 所有可用的网络设备名
    QList<QString> GetAllNetWorkName( void ) const;
    // 根据 网络设备名获取MAC地址
    QString GetNetWorkHardware(QString name);
    // 根据 IP获取MAC地址
    QString GetNetWorkHardware(QString ipaddress, IP ip);
    // 根据 IP获取广播地址
    QString GetNetWorkBroadcast(QString ipaddress, IP ip);
    // 根据 IP获取网络掩码
    QString GetNetWorkNetMask(QString ipaddress, IP ip);

private:
    struct NETWORKADDRESSENTRY {
        QString IpAddressV4;
        QString IpAddressV6;
        QString NetMask;
        QString Broadcast;
    };

    struct NETWORKINTERFACE {
        QString Name;
        QString Hardware;
        QList<NETWORKADDRESSENTRY> Entry;
    };

    void InitNetworkInterface( void );

signals:
    void LookupHost(QString host);
    void update_NetWorkIpv4(QList<QString>);
    void update_NetWorkIpv6(QList<QString>);

public slots:
    void Update_NetworkInterface( void );

    //void lookedUp(const QHostInfo &host);

private:
    QList<NETWORKINTERFACE> m_lNetworkimterface;
    QList<QString> m_lIpaddressIpv4;
    QList<QString> m_lIpaddressIpv6;
    QList<QString> m_lName;
};

#endif // CATNETWORK_H
